<template>
    <div>
        <a-modal :title="'用户类型'" :visible="visible" :confirm-loading="confirmLoading" @ok="handleOk"
            @cancel="handleCancel1">
            <div class="modelBox">
                <a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
                    <a-form-model-item label="类型名称">
                        <a-input v-model="form.name" />
                    </a-form-model-item>
                    <a-form-model-item label="类型权限">
                        <a-tree v-model="checkedKeys" checkable :expanded-keys="expandedKeys"
                            :auto-expand-parent="autoExpandParent" :selected-keys="selectedKeys" :tree-data="treeData"
                            @expand="treeOnExpand" @select="treeOnSelect" />
                    </a-form-model-item>
                </a-form-model>
            </div>
        </a-modal>
    </div>
</template>
<script>
const treeData = [
    {
        title: '数据统计',
        key: 'statistic',
    },
    {
        title: '商品管理',
        key: 'goodsMsg',
        children: [
            {
                title: '商品列表',
                key: 'goodsList',
                children: [
                    { title: '新增商品', key: 'GLadd' },
                    { title: '编辑', key: 'GLedit' },
                    { title: '删除', key: 'GLdel' },
                    { title: '采购', key: 'GLsale' },
                    { title: '新增规格', key: 'GLaddSku' },
                    { title: '删除规格', key: 'GLdelSku' },
                ],
            },
            {
                title: '平台商品',
                key: 'stageGoods',
            },
            {
                title: '商品分类',
                key: 'goodsCate',
                children: [
                    { title: '新增分类', key: 'GCadd' },
                    { title: '删除', key: 'GCdel' }
                ],
            },
            {
                title: '商品品牌',
                key: 'goodsBrand',
                children: [
                    { title: '新增品牌', key: 'GBadd' },
                    { title: '删除', key: 'GBdel' }
                ],
            },
            {
                title: '规格管理',
                key: 'skuMsg',
                children: [
                    { title: '新增规格', key: 'SMadd' },
                    { title: '删除', key: 'SMdel' }
                ],
            },
        ],
    },
    {
        title: '采购管理',
        key: 'saleMsg',
        children: [
            { title: '采购详情', key: 'SAdetail' },
            { title: '审核', key: 'SAapply' }
        ],
    },
    {
        title: '仓库管理',
        key: 'houseMsg',
        children: [
            {
                title: '仓库列表',
                key: 'houseList',
                children: [
                    { title: '新增仓库', key: 'HLadd' },
                    { title: '编辑', key: 'HLedit' },
                    { title: '删除', key: 'HLdel' }
                ],
            },
            {
                title: '库存管理',
                key: 'numsMsg',
                children: [
                    { title: '调拨', key: 'NMabet' },
                    { title: '销售', key: 'NMsale' }
                ],
            },
            {
                title: '调拨单',
                key: 'abetList',
                children: [
                    { title: '调拨单详情', key: 'ALdetail' },
                    { title: '审核', key: 'ALapply' }
                ],
            },
            {
                title: '销售单',
                key: 'saleList',
                children: [
                    { title: '销售单详情', key: 'SLdetail' },
                    { title: '审核', key: 'SLapply' }
                ],
            },
        ],
    },
    {
        title: '供应商管理',
        key: 'supplierMsg',
        children: [
            { title: '新增供应商', key: 'SUadd' },
            { title: '编辑', key: 'SUedit' },
            { title: '删除', key: 'SUdel' }
        ],
    },
    {
        title: '物流管理',
        key: 'logisticsMsg',
        children: [
            {
                title: '物流单价',
                key: 'weightMsg',
            },
            {
                title: '物流公司',
                key: 'companyMsg',
            }
        ],
    },
    {
        title: 'App管理',
        key: 'appMsg',
    },
    {
        title: '财务管理',
        key: 'moneyMsg',
    },
    {
        title: '售后管理',
        key: 'aferSaleMsg',
    },
    {
        title: '用户管理',
        key: 'userMsg',
        children: [
            {
                title: '用户列表',
                key: 'userList',
                children: [
                    { title: '新增用户', key: 'ULadd' },
                    { title: '编辑', key: 'ULedit' },
                    { title: '删除', key: 'ULdel' }
                ]
            },
            {
                title: '用户类型',
                key: 'userType',
                children: [
                    { title: '新增类型', key: 'UTadd' },
                    { title: '编辑', key: 'UTedit' },
                    { title: '删除', key: 'UTdel' }
                ]
            }
        ],
    },
];
import { addEditrole } from '../../http/api'
export default {
    name: "goodsBrandEdit",
    data() {
        return {
            visible: this.flag,
            confirmLoading: false,
            labelCol: { span: 4 },
            wrapperCol: { span: 16 },
            form: {
                name: '',
                id: '',
            },
            expandedKeys: ['goodsMsg', 'houseMsg', 'userMsg'],
            autoExpandParent: true,
            checkedKeys: [],
            selectedKeys: [],
            treeData,

            editType: 1, //1是新增 2是编辑
        };
    },
    props: ["flag", "list"],
    created() {
        if (this.list.length != 0) {
            this.form = {
                id: this.list.id,
                name: this.list.name,
            }
            this.checkedKeys = this.list.ids
            this.editType = 2
        } else {
            this.editType = 1
        }
    },
    watch: {
        checkedKeys(val) {
            console.log('onCheck', val);
        },
    },
    methods: {
        treeOnExpand(expandedKeys) {
            // console.log('onExpand', expandedKeys);
            this.expandedKeys = expandedKeys;
            this.autoExpandParent = false;
        },
        onCheck(checkedKeys) {
            // console.log('onCheck', checkedKeys);
            this.checkedKeys = checkedKeys;
        },
        treeOnSelect(selectedKeys, info) {
            // console.log('onSelect', info);
            this.selectedKeys = selectedKeys;
        },
        //确认
        handleOk(e) {
            this.confirmLoading = true;
            if (this.editType == 2) {
                this.addEditrole(this.form.id, this.checkedKeys, this.form.name);
            } else {
                this.addEditrole('', this.checkedKeys, this.form.name);
            }
        },
        //点击取消 关闭弹框赋值
        handleCancel1(e) {
            console.log("Clicked cancel button");
            this.visible = false;
            this.$emit("func", this.visible);
        },
        //点击确定 关闭弹框赋值
        closefz() {
            this.visible = false;
            this.confirmLoading = false;
            this.$emit("func", this.visible);
        },
        //添加分类
        async addEditrole(id, ids, name) {
            console.log(id, ids, name)
            var res = ''
            if (this.editType == 2) {
                res = await addEditrole({ id, ids, name });
            } else {
                res = await addEditrole({ ids, name });
            }
            console.log(res)
            if (res.status == 200) {
                this.$tishi("success", res.info);
                this.closefz()
            } else {
                this.$tishi("warning", res.info);
                this.confirmLoading = false;
            }
        },
    },
};
</script>

<style scoped>
.ant-upload-select-picture-card i {
    font-size: 32px;
    color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
    margin-top: 8px;
    color: #666;
}

.modelBox {
    width: 100%;
    height: 600rem;
    overflow-y: scroll;
}

.modelBox::-webkit-scrollbar {
    display: none;
}
</style>
